package xinyu.customer.widget.dialog;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.view.Window;

import xinyu.customer.R;

public class CustomPrtDialog  extends Dialog {
    /**
     * 显示的视图.
     */
    private View mView = null;

    /**
     * 屏幕变暗
     * @param context 上下文.
     */
    public CustomPrtDialog(Context context) {
        super(getParent(context));
        getWindow().setBackgroundDrawableResource(R.color.black_30);
    }

    /**
     * 屏幕不变暗
     * @param context 上下文
     * @param style 样式.
     */
    public CustomPrtDialog(Context context, int style) {
        //设置R.style.TANCStyle是为了让弹出的Dialog能否不使屏幕变暗
        super(getParent(context),style);
        getWindow().setBackgroundDrawableResource(R.color.blank);
    }

    private static Context getParent(Context context) {
        Context re = context;
        if (context instanceof Activity) {
            Activity activity = ((Activity)context);
            if (activity.isChild()) {
                activity = (Activity) getParent(activity.getParent());
            }
            re = activity;
        }
        return re;
    }

    public void setView(View view) {
        this.mView = view;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        if (mView != null) {
            setContentView(mView);
        }
    }

}